package de.baumann.browser.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import de.baumann.browser.OdinGlideModule;
import de.baumann.browser.R;

public class MultiCoverAdapter extends RecyclerView.Adapter<MultiCoverAdapter.MultiCoverHolder> {

    private Context mContext;
    private String[] urls;

    public MultiCoverAdapter(Context context, String url) {
        this.mContext = context;
        if (url.contains(",")) {
            urls = url.split(",");
        } else {
            urls = new String[]{url};
        }
    }

    @NonNull
    @Override
    public MultiCoverAdapter.MultiCoverHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       View rootView =  LayoutInflater.from(mContext).inflate(R.layout.item_multi_cover,parent,false);
        return new MultiCoverHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull MultiCoverAdapter.MultiCoverHolder holder, int position) {
        OdinGlideModule.loadWithRoundedCorners(mContext,urls[position],holder.ivMultiImg,R.drawable.shape_default_cover);
    }

    @Override
    public int getItemCount() {
        return urls.length;
    }

    public class MultiCoverHolder extends RecyclerView.ViewHolder{
        ImageView ivMultiImg;
        public MultiCoverHolder(View itemView) {
            super(itemView);
            ivMultiImg = itemView.findViewById(R.id.ivMultiImg);
        }
    }
}
